<template>
	<view>
		<view class="top-swiper">
			<view class="box">
				<swiper class="swiper" :previous-margin="swiper.margin" :next-margin='swiper.margin' :circular="true"
					@change="swiperChange">
					<swiper-item v-for="(item,index) in list" :key="index" class="swiper-item">
						<view :class="{'le-active':swiper.index == index, innerBox: true}">
							<view :class="{'coupon': true, 'checked': swiper.index === index}">
								<u-icon v-if="index === swiper.index" name="checkmark-circle-fill" class="checked-icon"
									size="30rpx" color="#FC602B"></u-icon>
								<image :src="item.icon" mode="aspectFit" class="image"></image>
								<text class="name">{{item.coupon_name}}</text>
								<text class="num">剩余{{item.surplus_num}}份</text>
							</view>
						</view>
					</swiper-item>
				</swiper>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			list: {
				type: Array,
				default: () => []
			}
		},
		data() {
			return {
				swiper: {
					margin: "210rpx",
					index: 0,
				}
			}
		},
		components: {

		},
		mounted() {

		},
		methods: {
			//swiper滑动事件
			swiperChange: function(e) {
				this.swiper.index = e.detail.current;
				this.$emit("swiperChange", this.swiper.index)
			},
		}
	}
</script>

<style lang="scss">
	.top-swiper {
		margin-bottom: 30rpx;

		.bg {
			box-sizing: content-box;
			width: 100%;
			position: relative;


		}

		.box {
			box-sizing: border-box;
			padding: 0;
		}

		.swiper {
			box-sizing: border-box;
			height: 280rpx;

			.le-img,
			.innerBox,
				{
				width: 100%;
				height: 100%;
				display: block;
				transform: scale(0.9);
				transition: all 0.3s ease-in-out 0s;
				border-radius: 4px;

				&.le-active {
					transform: scale(1);
				}
			}

			swiper-item {
				display: flex;
				align-items: center;
				justify-content: center;
			}

		}
	}

	.coupon {
		width: 100%;
		height: 100%;
		border-radius: 10rpx;
		border: 4rpx solid #999999;
		@extend .flex-center;
		flex-direction: column;
		font-size: 20rpx;
		color: #999999;
		box-sizing: border-box;
		transition: all linear .2s;
		position: relative;
		padding: 20rpx;
		padding-top: 48rpx;

		&.checked {
			border-color: #EE514C;
		}

		.checked-icon {
			position: absolute;
			right: 6rpx;
			top: 6rpx;
		}

		.name {
			margin: 30rpx 0 23rpx 0;
			font-size: 24rpx;
			font-weight: bold;
			color: #333333;
			text-align: center;
			white-space: nowrap;
		}

		image {
			width: 94rpx;
			height: 94rpx;
		}
	}
</style>
